From 29782e82f83ed000edecc56ac77285864ec2672b Mon Sep 17 00:00:00 2001
From: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Date: Sun, 12 Apr 2020 03:30:41 +0200
Subject: [PATCH libaio 07/11] Add SH support

Signed-off-by: Guillem Jover <guillem@hadrons.org>
---
 harness/main.c   | 2 +-
 src/libaio.h     | 3 ++-
 src/syscall-sh.h | 6 ++++++
 src/syscall.h    | 2 ++
 4 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 src/syscall-sh.h

diff --git a/harness/main.c b/harness/main.c
index 99d393f..ac0fba2 100644
--- a/harness/main.c
+++ b/harness/main.c
@@ -14,7 +14,7 @@
 #if __LP64__ == 0
 #if defined(__i386__) || defined(__powerpc__) || defined(__mips__)
 #define KERNEL_RW_POINTER	((void *)0xc0010000)
-#elif defined(__arm__) || defined(__m68k__) || defined(__s390__)
+#elif defined(__arm__) || defined(__m68k__) || defined(__s390__) || defined(__sh__)
 #define KERNEL_RW_POINTER	((void *)0x00010000)
 #elif defined(__hppa__)
 #define KERNEL_RW_POINTER	((void *)0x10100000)
diff --git a/src/libaio.h b/src/libaio.h
index 29005d0..c748454 100644
--- a/src/libaio.h
+++ b/src/libaio.h
@@ -52,7 +52,7 @@ typedef enum io_iocb_cmd {
 
 /* little endian, 32 bits */
 #if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \
-    defined(__sh__) || \
+    (defined(__sh__) && defined(__LITTLE_ENDIAN__)) || \
     defined(__bfin__) || \
     (defined(__MIPSEL__) && !defined(__mips64)) || \
     defined(__cris__) || (defined(__riscv) && __riscv_xlen == 32) || \
@@ -88,6 +88,7 @@ typedef enum io_iocb_cmd {
 /* big endian, 32 bits */
 #elif defined(__PPC__) || defined(__s390__) || \
       (defined(__arm__) && defined(__ARMEB__)) || \
+      (defined(__sh__) && defined (__BIG_ENDIAN__)) || \
       defined(__sparc__) || defined(__MIPSEB__) || defined(__m68k__) || \
       defined(__hppa__) || defined(__frv__) || defined(__avr32__) || \
       (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
diff --git a/src/syscall-sh.h b/src/syscall-sh.h
new file mode 100644
index 0000000..6c00573
--- /dev/null
+++ b/src/syscall-sh.h
@@ -0,0 +1,6 @@
+/* Copy from ./arch/sh/include/asm/unistd_32.h */
+#define __NR_io_setup       245
+#define __NR_io_destroy     246
+#define __NR_io_getevents   247
+#define __NR_io_submit      248
+#define __NR_io_cancel      249
diff --git a/src/syscall.h b/src/syscall.h
index a88876f..b86d745 100644
--- a/src/syscall.h
+++ b/src/syscall.h
@@ -33,6 +33,8 @@
 #include "syscall-parisc.h"
 #elif defined(__mips__)
 #include "syscall-mips.h"
+#elif defined(__sh__)
+#include "syscall-sh.h"
 #elif defined(__aarch64__) || defined(__riscv)
 #include "syscall-generic.h"
 #else
-- 
2.26.0.292.g33ef6b2f38

